import { http } from '@/server'
import type { HomeType } from '../home/interface'

/** 获取首页信息 */
export const fetchHomeData = async () => {
    try {
        const { data } = await http.get<HomeType.Data>('/engineer/home')
        return data
    } catch (error) {
        return undefined
    }
}

/** 获取讲师派遣任务 */
export const fetchDispatchTask = async (
    params?: Partial<{
        category_id: string
        is_confirm: string
        page: string
        per_page: string
    }>,
) => {
    try {
        const { data } = await http.get('/engineer/teacher/dispatch/task', {
            params: {
                page: 1,
                per_page: Number.MAX_SAFE_INTEGER,
                ...params,
            },
        })
        return data.list
    } catch (error) {
        return []
    }
}

/** 接受派遣任务 */
export const acceptTask = async (id: number) => {
    await http.post(`/engineer/teacher/confirm-task/${id}`, {
        is_confirm: 1,
    })
}

/** 培训评价列表 */
export const fetchEvaluateList = async (
    params?: Partial<{
        name: string
        form_type: string
        page: string
        per_page: string
    }>,
) => {
    try {
        const { data } = await http.get('/engineer/student/get-evaluate-data', {
            params: {
                page: 1,
                per_page: Number.MAX_SAFE_INTEGER,
                ...params,
            },
        })
        return data?.list ?? []
    } catch (error) {
        return []
    }
}
